﻿/**********************************************
 * 功能名称：成本及费用明细表
编写人：  杨莹
建立时间： 杨 2009年8月21日
说明：
查询显示“分成本细项”的成本台账信息。
 **************************************************************/

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hisun.Models;
using Hisun.Controllers;

namespace Hisun.View.ReportQuery
{
    public partial class Report_CBJFYMXB :AbcPageBase
    {
        HisunDBDataContext db = new HisunDBDataContext();
        public string alert;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                AbcFullAccountPeriod MyFullAp = new AbcFullAccountPeriod();

                MyFullAp.FullAccountPeriodToDropdownlist(DropDownList_Year, DropDownList_Month, Application["accountPeriod"].ToString());

            }
        }

        protected void Button_Query_Click(object sender, EventArgs e)
        {
            string MyQueryAccountPeriod = DropDownList_Year.SelectedValue.ToString() + DropDownList_Month.SelectedValue.ToString(); ;
            string CurrentUser = Session[ServerVars.sysSessionUserName].ToString();

            var IsValidString = from a in db.TABC_JS_AccountPeriods
                                where a.会计期间ID == MyQueryAccountPeriod
                                select a;
            if (IsValidString.Count() == 0)
            {
     
                alert = "<script>alert('会计期间不存在，请检查输入是否正确');</script>";
                return;
            }
            else if (IsValidString.Count() == 1)
            {
                CostReport MyReport = new CostReport();
                string myHtmlReport = "";
                myHtmlReport = MyReport.WriteExcel_Report_CBJFYMXB(MyQueryAccountPeriod, CurrentUser);
                Response.Redirect("/Report/UserReport/" + myHtmlReport + ".html");

            }
        }

        protected void Button_Printe_Click(object sender, EventArgs e)
        {
            string MyQueryAccountPeriod = DropDownList_Year.SelectedValue.ToString() + DropDownList_Month.SelectedValue.ToString(); ;
            string CurrentUser = Session[ServerVars.sysSessionUserName].ToString();

            var IsValidString = from a in db.TABC_JS_AccountPeriods
                                where a.会计期间ID == MyQueryAccountPeriod
                                select a;
            if (IsValidString.Count() == 0)
            {
                alert = "<script>alert('会计期间不存在，请检查输入是否正确');</script>";
                return;
            }
            else if (IsValidString.Count() == 1)
            {
                CostReport MyReport = new CostReport();
                string myHtmlReport = "";
                myHtmlReport = MyReport.WriteExcel_Report_CBJFYMXB(MyQueryAccountPeriod, CurrentUser);

                HttpResponse response = HttpContext.Current.Response;
                response.Clear();
                response.WriteFile("/Report/UserReport/" + myHtmlReport + ".xls");
                string httpHeader = "attachment;filename= CBJFYMXB" + MyQueryAccountPeriod + ".Xls";
                response.AppendHeader("Content-Disposition", httpHeader);
                response.Flush();



            }
        }
    }
}
